import { request } from '@/utils/request'

/**
 * 获取考试列表
 * @param {Object} params 查询参数
 * @param {number} params.page 页码
 * @param {number} params.size 每页数量
 * @param {string} params.status 状态：upcoming/ongoing/finished
 * @param {string} params.type 类型：quiz/exam/assignment
 * @param {string} params.courseId 课程ID
 */
export function getExamList(params) {
  return request.get('/exams', params)
}

/**
 * 获取我的考试列表
 * @param {Object} params 查询参数
 * @param {string} params.status 状态：pending/completed/missed
 */
export function getMyExams(params) {
  return request.get('/exams/my', params)
}

/**
 * 获取考试详情
 * @param {string} examId 考试ID
 */
export function getExamDetail(examId) {
  return request.get(`/exams/${examId}`)
}

/**
 * 开始考试
 * @param {string} examId 考试ID
 */
export function startExam(examId) {
  return request.post(`/exams/${examId}/start`)
}

/**
 * 获取考试试题
 * @param {string} examId 考试ID
 * @param {string} sessionId 考试会话ID
 */
export function getExamQuestions(examId, sessionId) {
  return request.get(`/exams/${examId}/questions`, { sessionId })
}

/**
 * 提交单题答案
 * @param {string} examId 考试ID
 * @param {string} questionId 题目ID
 * @param {Object} data 答案数据
 * @param {string} data.sessionId 考试会话ID
 * @param {any} data.answer 答案
 * @param {number} data.timeSpent 用时（秒）
 */
export function submitQuestionAnswer(examId, questionId, data) {
  return request.post(`/exams/${examId}/questions/${questionId}/answer`, data)
}

/**
 * 提交考试
 * @param {string} examId 考试ID
 * @param {Object} data 提交数据
 * @param {string} data.sessionId 考试会话ID
 * @param {Array} data.answers 所有答案
 * @param {number} data.totalTime 总用时
 */
export function submitExam(examId, data) {
  return request.post(`/exams/${examId}/submit`, data)
}

/**
 * 获取考试结果
 * @param {string} examId 考试ID
 * @param {string} sessionId 考试会话ID
 */
export function getExamResult(examId, sessionId) {
  return request.get(`/exams/${examId}/result`, { sessionId })
}

/**
 * 获取考试记录列表
 * @param {Object} params 查询参数
 * @param {number} params.page 页码
 * @param {number} params.size 每页数量
 * @param {string} params.courseId 课程ID
 * @param {string} params.examType 考试类型
 */
export function getExamRecords(params) {
  return request.get('/exams/records', params)
}

/**
 * 获取考试记录详情
 * @param {string} recordId 记录ID
 */
export function getExamRecordDetail(recordId) {
  return request.get(`/exams/records/${recordId}`)
}

/**
 * 获取错题本
 * @param {Object} params 查询参数
 * @param {number} params.page 页码
 * @param {number} params.size 每页数量
 * @param {string} params.subject 科目
 * @param {string} params.questionType 题型
 */
export function getWrongQuestions(params) {
  return request.get('/exams/wrong-questions', params)
}

/**
 * 移除错题
 * @param {string} questionId 题目ID
 */
export function removeWrongQuestion(questionId) {
  return request.delete(`/exams/wrong-questions/${questionId}`)
}

/**
 * 练习错题
 * @param {Array} questionIds 题目ID列表
 */
export function practiceWrongQuestions(questionIds) {
  return request.post('/exams/practice/wrong-questions', { questionIds })
}

/**
 * 获取练习题
 * @param {Object} params 参数
 * @param {string} params.subject 科目
 * @param {string} params.chapter 章节
 * @param {string} params.difficulty 难度
 * @param {number} params.count 题目数量
 * @param {Array} params.questionTypes 题型列表
 */
export function getPracticeQuestions(params) {
  return request.get('/exams/practice/questions', params)
}

/**
 * 开始练习
 * @param {Object} data 练习数据
 * @param {Array} data.questionIds 题目ID列表
 * @param {string} data.practiceType 练习类型
 */
export function startPractice(data) {
  return request.post('/exams/practice/start', data)
}

/**
 * 提交练习答案
 * @param {string} practiceId 练习ID
 * @param {Object} data 答案数据
 */
export function submitPracticeAnswer(practiceId, data) {
  return request.post(`/exams/practice/${practiceId}/submit`, data)
}

/**
 * 获取练习结果
 * @param {string} practiceId 练习ID
 */
export function getPracticeResult(practiceId) {
  return request.get(`/exams/practice/${practiceId}/result`)
}

/**
 * 获取模拟考试列表
 * @param {Object} params 查询参数
 * @param {string} params.subject 科目
 * @param {string} params.level 难度等级
 */
export function getMockExams(params) {
  return request.get('/exams/mock', params)
}

/**
 * 开始模拟考试
 * @param {string} mockExamId 模拟考试ID
 */
export function startMockExam(mockExamId) {
  return request.post(`/exams/mock/${mockExamId}/start`)
}

/**
 * 获取考试统计信息
 * @param {Object} params 查询参数
 * @param {string} params.timeRange 时间范围
 * @param {string} params.subject 科目
 */
export function getExamStats(params) {
  return request.get('/exams/stats', params)
}

/**
 * 获取知识点掌握情况
 * @param {string} courseId 课程ID
 */
export function getKnowledgePoints(courseId) {
  return request.get(`/exams/knowledge-points`, { courseId })
}

/**
 * 获取学习建议
 * @param {string} courseId 课程ID
 */
export function getStudySuggestions(courseId) {
  return request.get(`/exams/study-suggestions`, { courseId })
}

/**
 * 收藏题目
 * @param {string} questionId 题目ID
 */
export function favoriteQuestion(questionId) {
  return request.post(`/exams/questions/${questionId}/favorite`)
}

/**
 * 取消收藏题目
 * @param {string} questionId 题目ID
 */
export function unfavoriteQuestion(questionId) {
  return request.delete(`/exams/questions/${questionId}/favorite`)
}

/**
 * 获取收藏的题目
 * @param {Object} params 查询参数
 */
export function getFavoriteQuestions(params) {
  return request.get('/exams/favorite-questions', params)
}

/**
 * 举报题目
 * @param {string} questionId 题目ID
 * @param {Object} data 举报数据
 * @param {string} data.reason 举报原因
 * @param {string} data.description 详细描述
 */
export function reportQuestion(questionId, data) {
  return request.post(`/exams/questions/${questionId}/report`, data)
}

/**
 * 获取题目解析
 * @param {string} questionId 题目ID
 */
export function getQuestionAnalysis(questionId) {
  return request.get(`/exams/questions/${questionId}/analysis`)
}

/**
 * 获取相似题目
 * @param {string} questionId 题目ID
 * @param {number} limit 数量限制
 */
export function getSimilarQuestions(questionId, limit = 5) {
  return request.get(`/exams/questions/${questionId}/similar`, { limit })
}

/**
 * 获取考试日历
 * @param {Object} params 查询参数
 * @param {string} params.year 年份
 * @param {string} params.month 月份
 */
export function getExamCalendar(params) {
  return request.get('/exams/calendar', params)
}

/**
 * 设置考试提醒
 * @param {string} examId 考试ID
 * @param {Object} data 提醒设置
 * @param {boolean} data.enabled 是否启用
 * @param {number} data.advanceTime 提前时间（分钟）
 */
export function setExamReminder(examId, data) {
  return request.post(`/exams/${examId}/reminder`, data)
}

/**
 * 获取考试提醒设置
 * @param {string} examId 考试ID
 */
export function getExamReminder(examId) {
  return request.get(`/exams/${examId}/reminder`)
}